package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.RechargePriceList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

public interface RechargePriceListRepository extends JpaRepository<RechargePriceList, Integer> {
    // 排序查询充值列表
    @Query(value = "select r from RechargePriceList r order by r.money asc ")
    @Modifying
    List<RechargePriceList> findAllByDesc();

    @Transactional
    @Modifying
    @Query(value = "update RechargePriceList r set r.money = :#{#recharge.money}, r.productId = :#{#recharge.productId}, r.studyCoin = :#{#recharge.studyCoin} where r.id = :#{#recharge.id}")
    void updateById(@Param("recharge") RechargePriceList rechargePriceList);

    //根据productId查询数据
    RechargePriceList findAllByProductId(String productId);
}
